package com.leapp.sk.ui.activity.personal

import android.os.Bundle
import cc.vv.lkbasecomponent.http.LKHttp
import cc.vv.lkbasecomponent.http.lib.setting.Settings
import cc.vv.lklibrary.http.base.okhttpfactory.plugins.httpplugin.MediaTypeWrap
import com.example.baselibrary.util.LKToastUtil
import com.example.mvp.activity.BaseActivityMVP
import com.example.mvp.binder.BaseDataBinder
import com.leapp.sk.R
import com.leapp.sk.app.CONCAT_TEACHER
import com.leapp.sk.bean.ConcatTeacherDataEntity
import com.leapp.sk.bean.request.personal.ConcatTeacherRequestEntity
import com.leapp.sk.bean.response.personal.ConcatTeacherResponseEntity
import com.leapp.sk.binder.BaseBinder
import com.leapp.sk.sever.personal.ConcatTeacherSever
import com.example.util.finallist.SKCODE_200
import com.leapp.sk.viewdelegate.personal.ContactTecherDelegate

/**
 * 联系老师
 * @author  chaohaipeng  on 2018/8/8.
 */
class ContactTecherActivity:BaseActivityMVP<ContactTecherDelegate>() {
    /**
     * 数据
     */
    val mutableListOf = mutableListOf<ConcatTeacherDataEntity>()
    override fun initDate() {
        viewDelegate.initAdapter(mutableListOf)
        httpTeacher()
    }

    override fun bindEvenListener() {
    }

    override fun getDelegateClass(): Class<ContactTecherDelegate> {
        return ContactTecherDelegate::class.java
    }

    override fun getDataBinder(): BaseDataBinder<*, *> {
        return BaseBinder()
    }

    override fun initView(p0: Bundle?) {
        viewDelegate.setTitle(resources.getString(R.string.string_contanct_techer))
    }

    /**
     * 获取个人信息
     */
    private fun httpTeacher() {
        val concatTeacherRequestEntity = ConcatTeacherRequestEntity()
        concatTeacherRequestEntity.id=concatTeacherRequestEntity.userId
        LKHttp.post(CONCAT_TEACHER, concatTeacherRequestEntity, ConcatTeacherResponseEntity::class.java, object : BaseCallBack<ConcatTeacherResponseEntity>(this) {
            override fun onSuccess(url: String?, resultText: String?, obj: ConcatTeacherResponseEntity?) {
                super.onSuccess(url, resultText, obj)
                if (obj?.code == SKCODE_200) {
                    val contanctData = ConcatTeacherSever.getInstance().getContanctData(obj)
                    mutableListOf.addAll(contanctData)
                    viewDelegate?.notifyAdapter()
                }else{
                    LKToastUtil.showToastShort(obj?.message)
                }
            }
            override fun onFailure(url: String?, isLoading: Boolean, exceptionStr: String?) {
                super.onFailure(url, isLoading, exceptionStr)
                LKToastUtil.showToastShort(resources.getString(R.string.app_net_erro))
            }
        }
                , true, Settings(MediaTypeWrap.MEDIA_TYPE_FORM))

    }


}